import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'
import { Observable, map } from 'rxjs'
interface data<T> {
  data: T
}

//Rxjs 格式化数据
@Injectable()
export class PostInterceptor<T = any> implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<data<T>> {
    return next.handle().pipe(
      map((data) => ({
        data,
        status: 0,
        message: data.message || 'success'
      }))
    )
  }
}
